package com.app.acitivty;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.SimpleAdapter;

import com.app.activity.R;
import com.app.components.TopMenu;
import com.app.data.DataGeneration;
import com.app.data.InnItem;
import com.app.data.LineItem;
import com.app.data.ListDataModel;
import com.app.data.ScenicItem;
import com.app.data.TicketItem;
import com.app.data.YouhuiItem;
import com.app.service.HotelService;
import com.app.service.HttpCallBack;
import com.app.service.adapter.HotelAdapter;
import com.app.utils.ActivityTools;
import com.app.utils.GlobalConstants;

public class InnListSearchActivity extends Activity implements OnItemClickListener, HttpCallBack {

	private ArrayList<InnItem> hotels;
	private ArrayList<HashMap<String, String>> mInnListItems = null;

	private String[] mColumnNames = { "innIcon", "innName", "innAddress",
			"innStarLevel", "innPrice" };

	private int[] mViewIds = { R.id.imgInnIcon, R.id.tvInnName,
			R.id.tvInnAddress, R.id.imgInnStarLevel, R.id.tvInnPrice };

	private ListView listview;

	private Button btnFootSearch;
	
	
	private LinearLayout linearLayout;
	ProgressDialog progressDialog;


 

	public static HashMap addItem(InnItem item) {
		HashMap<Object, Object> map = new HashMap<Object, Object>();
		map.put("innIcon", item.getDrawId());
		map.put("innName", item.getName());
		map.put("innAddress", item.getSite());
		map.put("innStarLevel", item.getLeveldrawId());
		map.put("innPrice", item.getMoney());
		return map;
	}

	@SuppressWarnings("unchecked")
	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.inn_list_search);
		btnFootSearch=(Button) findViewById(R.id.btnSearch);
		btnFootSearch.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				ActivityTools.gotoActivity(InnListSearchActivity.this,
						InnScheduledActivity.class);

			}
		});

		TopMenu topMenu = new TopMenu(this, "预定客栈", new OnClickListener() {

			@Override
			public void onClick(View v) {
				// 跳转到预定客栈页面
				InnListSearchActivity.this.finish();
				// ActivityTools.gotoActivity(InnListActivity.this,
				// InnScheduledActivity.class);
			}
		}, R.drawable.top_button_unselect, R.drawable.top_button_selected,
				"客栈列表",80);
		topMenu.onCreate();

		ArrayList<ListDataModel> detailItems = DataGeneration
				.getHotelTestInfo(9);

		int len = detailItems.size();

		mInnListItems = new ArrayList<HashMap<String, String>>();

		for (int i = 0; i < len; i++) {
			mInnListItems.add(addItem((InnItem) detailItems.get(i)));
		}

		ListAdapter la = new SimpleAdapter(this, mInnListItems,
				R.layout.inn_list_item, mColumnNames, mViewIds);

		listview = (ListView) findViewById(R.id.lvInnList);
		
		
		progressDialog = new ProgressDialog(this);
		progressDialog.setTitle("提示");
		progressDialog.setMessage("读取数据中...");
		progressDialog.setCancelable(false);
		progressDialog.setIndeterminate(true);
		progressDialog.show();
		HotelService service = new HotelService(this);
		service.execute("");
		
		listview.setOnItemClickListener(this);
		//listview.setAdapter(la); 
		//listview.setOnItemClickListener(new OnItemClickListener() 
//		{
//			@Override
//			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
//					long arg3) {
//				ActivityTools.gotoActivity(InnListSearchActivity.this, InnDetailActivity.class);
//				
//			}
//		});


	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View v, int pos, long arg3) {
		InnItem item = hotels.get(pos);
		GlobalConstants.getInstance().setInnitem(item);
		ActivityTools.gotoActivity(this, InnDetailActivity.class);
	}

	
	@Override
	public void hotelFinishLoad(int code, ArrayList<InnItem> list) {
		//System.out.println("hotelFinishLoad code:"+code);
		progressDialog.hide();
		progressDialog.dismiss();
		hotels = list;
		HotelAdapter adapter = new HotelAdapter(this,list);

		listview.setAdapter(adapter);
	}

	

	@Override
	public void lineFinishLoad(int code, ArrayList<LineItem> list) {
		
	}

	@Override
	public void ticketFinishLoad(int code, ArrayList<ScenicItem> list) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void youhuiFinishLoad(int code, ArrayList<YouhuiItem> list) {
		// TODO Auto-generated method stub
		
	}

	
	

}
